#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
using namespace std;

int T,n,a[1000006],c[1000006],ans;
bool bo[1000006];

void dfs(int x){
    if(x>n){
        int re=-1,bl=-1,cnt=0;
        for(int i=1;i<=n;i++){
            if(bo[i]){
                if(re!=-1){
                    if(a[i]==a[re]){
                        cnt+=a[i];
                    }
                }
                re=i;
            }else{
                if(bl!=-1){
                    if(a[i]==a[bl]){
                        cnt+=a[i];
                    }
                }
                bl=i;
            }
        }
        if(ans<cnt){
            ans=cnt;
        }
        return;
    }
    dfs(x+1);
    bo[x]=true;
    dfs(x+1);
    bo[x]=false;
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        ans=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        dfs(1);
        cout<<ans<<"\n";
    }
	return 0;
}
